/*
 * @lc app=leetcode.cn id=2138 lang=typescript
 *
 * [2138] 将字符串拆分为若干长度为 k 的组
 */

// @lc code=start
function divideString(s: string, k: number, fill: string): string[] {
    const last = s.length % k;
    let count = Math.floor(s.length / k);
    let stack: string[] = [];
    while (count) {
        const str = s.slice((count - 1) * k, count * k);
        stack.unshift(str);
        count--;
    }
    count = Math.floor(s.length / k);
    if (last !== 0) {
        let lastItem = s.slice(count * k) + fill.repeat(k - last);
        stack.push(lastItem);
    }
    return stack;
}
// @lc code=end
